package cn.edu.hbwe.book.admin.service.notices;

import java.sql.SQLException;
import java.util.List;

import cn.edu.hbwe.book.admin.dao.NoticeDao;
import cn.edu.hbwe.book.entity.Notice;

public class NoticesService {
	private NoticeDao dao = new NoticeDao();

	// 查询所有公告
	public List<Notice> getAllNotices() {
		try {
			return dao.getAllNotices();
		} catch (SQLException e) {
			throw new RuntimeException("查询所有的公告失败！");
		}
	}

	// 根据id查找公告
	public Notice findNoticeById(String n_id) {
		try {
			return dao.findNoticeById(n_id);
		} catch (SQLException e) {
			throw new RuntimeException("根据id查找公告失败！");
		}
	}

	// 添加公告
	public void addNotice(Notice n) {
		try {
			dao.addNotice(n);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException("添加公告失败!");
		}
	}

	// 根据id修改公告
	public void updateNotice(Notice n) {
		try {
			dao.updateNotice(n);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	// 根据id删除公告
	public void deleteNotice(String n_id) {
		try {
			dao.deleteNotice(n_id);
		} catch (SQLException e) {
			throw new RuntimeException("根据id删除公告失败！");
		}
	}

}
